{include file="header/index" /}
		<div class="container whitebg">
			<div class="topnav clearfix">
				<div class="title fl">
					<h3>编辑运营中心</h3>
				</div>
			</div>
			<p class="add_title">基本信息</p>
			<!--<form class="form-horizontal" id="operation">-->
			<form class="form-horizontal"  id="operation" enctype="multipart/form-data">
				<div class="form-group displaycenter upload_header">
					<label class="col-sm-2 control-label">头像</label>
					<div class="col-sm-10 displaycenter">
						<div class="uploadheader">
							<div class="btn btn-default pointer">选择头像</div>
							<input type="file" name="avatar_img" id="avatar_img" class="webuploader-element-invisible" multiple="multiple" onchange="uploadFile()" accept="image/jpg,image/jpeg,image/png">
						</div>
						<img id="img" src="{if condition='(empty($admin))'}__IMG__/head_default.gif{else /}{:Config('IMAGES_PATH')}{$admin.avatar_img}{/if}" class="upload_IMG img-circle" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">帐号</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" placeholder="请输入登录账号" id="admin_account" name="admin_account" {if condition='(!empty($admin.account))'}readonly="readonly"{/if} id="account" value="{if condition='(empty($admin))'}{else /}{$admin.account}{/if}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">密码</label>
					<div class="col-sm-4">
						<input type="text" placeholder="请输入登录密码" maxlength="20" minlength="6" class="form-control" name="admin_password" id="password" value="">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">邮箱</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" placeholder="请输入邮箱" name="admin_email" id="email" value="{if condition='(empty($admin))'}{else /}{$admin.email}{/if}">
					</div>
				</div>
				<div class="form-group">
					<label for="Operationcenter" class="col-sm-2 control-label">运营中心名称</label>
					<div class="col-sm-4">
						<input type="text" name="company_name" placeholder="请输入运营中心名称" class="form-control" id="Operationcenter" value="{if condition='(empty($data))'}{else /}{$data.company_name}{/if}">
					</div>
				</div>
				<input type="hidden" id="o_id" name="o_id" value="{if condition='(empty($data))'}
						{else /}{$data.o_id}{/if}">
				<div class="form-group">
					<label for="EngineeringDepartment" class="col-sm-2 control-label">负责区域</label>
					<div class="col-sm-8 choosecity">
						<label class="fl control-label mr10">省</label>
						<select name="province_id" id="province">
							<option value="">选择省份</option>
							{volist name="Province" id="pr"}
							<option value="{$pr.id}" {if condition='((isset($data)) AND ($pr.id == $data.province_id))'}selected{else /}{/if}>{$pr.area_name}</option>
							{/volist}
						</select>
						<input type="hidden" name="province_name" id="province_name" value="">
					</div>
				</div>
				<div class="form-group">
					<label for="address" class="col-sm-2 control-label">详细地址</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" placeholder="请输入详细地址" id="address" name="address" value="{if condition='(empty($data))'}
						{else /}{$data.address}{/if}">
					</div>
				</div>
				<div class="form-group">
					<label for="name" class="col-sm-2 control-label">联系人</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="name" placeholder="请输入联系人" id="name" value="{if condition='(empty($data))'}
						{else /}{$data.name}{/if}">
					</div>
				</div>
				<div class="form-group">
					<label for="phone" class="col-sm-2 control-label">电话</label>
					<div class="col-sm-4">
						<input type="text" maxlength="11" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();" minlength="11" name="phone" placeholder="请输入联系电话" class="form-control" id="phone" value="{if condition='(empty($data))'}
						{else /}{$data.phone}{/if}">
					</div>
				</div>
				<div class="form-group">
					<label for="Remarks" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-5">
						<textarea class="form-control" name="note" id="Remarks" rows="3" placeholder="请输入备注信息" onkeydown="checkMaxInput(this,100)" onkeyup="checkMaxInput(this,100)" onfocus="checkMaxInput(this,100)" onblur="checkMaxInput(this,100);resetMaxmsg()">{if condition='(empty($data))'}{else /}{$data.note}{/if}</textarea>
					</div>
				</div>
			</form>
			<form class="form-inline btnlists">
				<button id="but" type="button" class="btn btn-primary">保存</button>
				<a class="btn btn-default" href="{:url('operationmanagement/index')}">返回</a>
			</form>
		</div>


</body>

</html>
<script type="text/javascript">
    //运营中心绑定
    function uploadFile() {
        var file = document.getElementById("avatar_img").files[0];
        var reader = new FileReader();
        reader.onload = function(e) {
            img.src = this.result;
        };
        reader.readAsDataURL(file); //Base64
    }
    function bindAccountOperation(id) {
        $("#o_id").val(id);
        $("#img").attr('src',"__IMG__/head_default.gif");
        $("#form_operation")[0].reset();
        $.post("{:url('Operationmanagement/bindAccountOperation')}",{o_id:id},function (data) {
            if (data.code == 1){
                $("#admin_account").css('display','none');
                $("#img").attr('src',"{:Config('IMAGES_PATH')}"+data.data.avatar_img);
                $("#account").val(data.data.account);
                $("#email").val(data.data.email);
                $("#admin_name").val(data.data.name);
                $("#admin_phone").val(data.data.phone);
                $("#address").val(data.data.address);
            }else {
                $("#admin_account").css('display','');
            }
        });
        $("#admin_account").click(function () {
            var formData = new FormData($( "#form_operation" )[0]);
            $.ajax({
                url:  "{:url('Operationmanagement/bindAccountOperation')}",
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                dataType : 'json',
                success: function (returndata) {
                    if(returndata.code == '1'){
                        layer.msg(returndata.msg, {icon: 1,time: 2000},function(){history.back();});
                    }else{
                        layer.msg(returndata.msg, {icon: 2,time: 2000},function(){history.back();});
                    }

                },error: function (returndata) {
                    layer.msg('数据异常', {icon: 2,time: 2000});
                    return false;
                }
            });

        });
    }

	$("#but").click(function () {
        //验证数据
        var message = '';
        if ($("#admin_account").val() == ''){
            message = '账号不能为空';
        }else if ($("#email").val() == ''){
            message = '邮箱不能为空';
        }else if ($("#Operationcenter").val() == ''){
            message = '运营中心名称不能为空';
        }else if ($("#province").val() == ''){
            message = '省不能为空';
        }else if ($("#address").val() == ''){
            message = '详细地址不能为空';
        }else if ($("#name").val() == ''){
            message = '联系人不能为空';
        }else if ($("#phone").val() == ''){
            message = '电话不能为空';
        }
        if (message != ''){
            parent.layer.msg(message, {icon: 2,time: 2000},function(){});
            return false;
        }

	    if ($("#admin_account").val() == ''){
            layer.msg("请绑定账号", {icon: 7,time: 3000},function(){});
			return false;
		}
		$("#province_name").val($("#province option:selected").text());
        var operation = new FormData($("#operation")[0]);
        $.ajax({
            url:  "{:url('Operationmanagement/doEditOperation')}",
            type: 'POST',
            data: operation,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            dataType : 'json',
            success: function (returndata) {
                if(returndata.code == '1'){
                    layer.msg(returndata.msg, {icon: 1,time: 2000},function(){history.back();});
                }else{
                    layer.msg(returndata.msg, {icon: 2,time: 2000},function(){});
                }

            },error: function (returndata) {
                layer.msg('数据异常', {icon: 2,time: 2000});
                return false;
            }
        });
//		$.get("{:url('Operationmanagement/doEditOperation')}",{formData:formData,company_name:company_name,province_id:province_id,province_name:province_name,city_id:city_id,city_name:city_name,address:address,name:name,phone:phone,note:Remarks,o_id:o_id},function (flag) {
//			console.log(flag);
//		    if (flag.code == 0){
//                layer.confirm(flag.msg, {
//                    btn: ['确认'] //按钮
//                });
//			}else {
//                layer.confirm(flag.msg, {
//                    btn: ['确认'] //按钮
//                }, function(){
//                    history.back();
//                });
//			}
//        })
    });
	//多行文本输入框剩余字数计算  
	function checkMaxInput(obj, maxLen) {
		if(obj == null || obj == undefined || obj == "") {
			return;
		}
		if(maxLen == null || maxLen == undefined || maxLen == "") {
			maxLen = 100;
		}

		var strResult;
		var $obj = $(obj);
		var newid = $obj.attr("id") + 'msg';

		if(obj.value.length > maxLen) { //如果输入的字数超过了限制  
			obj.value = obj.value.substring(0, maxLen); //就去掉多余的字  
			strResult = '<span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span>'; //计算并显示剩余字数  
		} else {
			strResult = '<span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span>'; //计算并显示剩余字数  
		}

		var $msg = $("#" + newid);
		if($msg.length == 0) {
			$obj.after(strResult);
		} else {
			$msg.html(strResult);
		}
	}

	//清空剩除字数提醒信息  
	function resetMaxmsg() {
		$("span.Max_msg").remove();
	}





</script>